package com.neusoft.nepb.controller;

import com.neusoft.nepb.common.FileUtils;
import com.neusoft.nepb.common.SceneUtils;
import com.neusoft.nepb.entity.Data;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class InfoSaveViewController {
    @FXML
    TableView tableView;
    @FXML
    TableColumn<Date, Data> degree,time,province,city,district,info,detailAddress;
    @FXML
    ImageView imageView;

    private ObservableList tableList = FXCollections.observableArrayList();

    private Map finalDataMap = new HashMap();

    @FXML
    public void initialize(){
        //初始化图像
        SceneUtils.setImage(imageView,"/com/neusoft/nepb/image/forest.jpg");
        //初始化表格内容
        tableView.setItems(tableList);
        degree.setCellValueFactory(new PropertyValueFactory<>("degree"));
        time.setCellValueFactory(new PropertyValueFactory<>("time"));
        province.setCellValueFactory(new PropertyValueFactory<>("province"));
        city.setCellValueFactory(new PropertyValueFactory<>("city"));
        district.setCellValueFactory(new PropertyValueFactory<>("district"));
        detailAddress.setCellValueFactory(new PropertyValueFactory<>("detailAddress"));
        info.setCellValueFactory(new PropertyValueFactory<>("info"));
        finalDataMap = FileUtils.readMapObject("finalMap.txt");
        tableList.addAll(finalDataMap.values());
    }

    public void back(ActionEvent event) throws IOException {
        SceneUtils.switchTo(event,"/com/neusoft/nepb/view/SeclectNetView.fxml");
    }
}
